package com.example.tool.entity;

import com.alibaba.fastjson2.JSONObject;
import javafx.util.Pair;
import org.apache.commons.lang3.BooleanUtils;

import java.util.function.Function;

public interface TableViewEnum {
    enum TableTitle {
        ID("id", "任务id", true,true),
        ACCOUNT_ID("accountId", "账号", true),
        SHOP_ID("shopIds", "店铺", true),
        APP_ID("appId", "应用", false, true),
        PLATFORM("platform", "平台", true, true),
        SERVICE_NAME("serviceName", "服务", true, true),
        SERVICE_PORT("servicePort", "端口", false, true),
        SOURCE("source", "来源", true),
        FOOD_NAME("foodName", "菜品名称", true),

        PARENT_TASK_ID("parentTaskId","父任务id",true,true),
        CLASS_NAME("className","类名",true,true),
        METHOD_NAME("methodName","方法名",true,true),

        REMARK("remark","备注",false,false),


        TASK_TYPE("taskType", "事件", false, (pair) -> {
            if ("1".equals(pair.getKey().getString(pair.getValue())))
                return "历史推广";
            else if ("2".equals(pair.getKey().getString(pair.getValue())))
                return "实时推广";
            else
                return "其他";
        }),
        TASK_STATUS("status", "状态", true, (pair) -> {
            if ("1".equals(pair.getKey().getString(pair.getValue())))
                return "成功";
            else
                return "失败";
        }),

        TASK_STAGE("stage", "阶段", true, (pair) -> {
            if ("0".equals(pair.getKey().getString(pair.getValue())))
                return "开始";
            else if ("1".equals(pair.getKey().getString(pair.getValue())))
                return "中间阶段";
            else
                return "结束";
        }),

        TASK_FINISH("finish", "进度", true, (pair) -> {
            if (BooleanUtils.toBoolean(pair.getKey().getString(pair.getValue())))
                return "完成";
            else
                return "执行中";
        }),

        TASK_COST("cost", "消耗[ms]", true),

        START_TIME("startTime", "开始", true),

        END_TIME("endTime", "结束", true),

        RUN_TIME("runDate", "执行日期", true),

        DATA("data", "内容", false, true, JSONObject::toJSONString);

        private String code;

        private String title;

        private boolean sort;

        private boolean hide = false;
        Function<Pair<JSONObject, String>, String> mapper = pair -> pair.getKey().getString(pair.getValue());

        TableTitle(String code, String title, boolean sort) {
            this.code = code;
            this.title = title;
            this.sort = sort;
        }

        TableTitle(String code, String title, boolean sort, boolean hide) {
            this(code,title,sort);
            this.hide = hide;
        }

        TableTitle(String code, String title, boolean sort, boolean hide, Function<Pair<JSONObject, String>, String> mapper) {
            this(code,title,sort,hide);
            this.mapper = mapper;
        }

        TableTitle(String code, String title, boolean sort, Function<Pair<JSONObject, String>, String> mapper) {
            this(code,title,sort);
            this.mapper = mapper;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public boolean isSort() {
            return sort;
        }

        public void setSort(boolean sort) {
            this.sort = sort;
        }

        public boolean isHide() {
            return hide;
        }

        public void setHide(boolean hide) {
            this.hide = hide;
        }

        public Function<Pair<JSONObject, String>, String> getMapper() {
            return mapper;
        }

        public void setMapper(Function<Pair<JSONObject, String>, String> mapper) {
            this.mapper = mapper;
        }
    }

}
